<?php


namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Doctrine\DBAL\Schema\AbstractAsset;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class StorageController extends Controller
{
    
    public function uploadImage(Request $request){

        $images = $request->file('image');
        if(is_null($images)){
            return $this->ajaxError('獲取失敗，請從新上傳');
        }
        $path = preg_replace('#^public/#', '', $images->storePublicly('public/image'));
        $string = Storage::url(substr(strstr($path,'/'),1));
        $string = env('APP_URL').'/public'.$string;
        if($string){
            return $this->ajaxSuccess($string);
        }else{
            return $this->ajaxError();
        }

    }

}
